<template>
  <div>
    <slot :name="`form-${props.component.dataIndex}`" v-bind="props.component">
      <a-button
        :disabled="props.component.disabled"
        :href="props.component.href"
        :html-type="props.component.htmlType"
        :loading="props.component.loading"
        :long="props.component.long"
        :shape="props.component.shape"
        :size="props.component.size"
        :status="props.component.status"
        :type="props.component.type"
        @click="rv('onClick')"
      >
        <template v-if="props.component.icon" #icon>
          <component :is="props.component.icon" />
        </template>
        {{ props.component.title ?? "button" }}
      </a-button>
    </slot>
  </div>
</template>

<script setup>
import { runEvent } from "@/components/MaForm/types/event";

const props = defineProps({
  component: Object
});

const formModel = inject("formModel");
const getColumnService = inject("getColumnService");
const columns = inject("columns");
const rv = async (ev, value = undefined) =>
  await runEvent(
    props.component,
    ev,
    {
      formModel,
      getColumnService,
      columns
    },
    value
  );

rv("onCreated");
onMounted(() => rv("onMounted"));
</script>
